import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/movie")
public class MovieServlet extends HttpServlet {
	private MovieDao movieDao;

	@Override
	public void init() throws ServletException {
		movieDao = new MovieDao();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=utf-8");
		req.setCharacterEncoding("utf-8");
		List<Movie> movieList = movieDao.findAll();
		String jsonStr = JSONUtil.toJsonStr(movieList);
		resp.getWriter().write(jsonStr);
		resp.getWriter().close();
	}
}